//
//  WBFristPageRetweetedView.swift
//  weibo
//
//  Created by  郭航 on 16/6/29.
//  Copyright © 2016年 郭航. All rights reserved.
//

import UIKit
import SnapKit

class WBFristPageRetweetedView: UIView {
    
    var dataModel: WBFristPageDataModel? {
        didSet {
            textLabel.attributedText = dataModel?.retweeted_status?.textAttr
            
            if dataModel?.retweeted_status?.pic_urls?.count > 0 {
                pictureView.dataModel = dataModel?.retweeted_status?.pic_urls
                
                selfBottomConstraints?.uninstall()
                self.snp_makeConstraints { (make) in
                    selfBottomConstraints = make.bottom.equalTo(pictureView.snp_bottom).offset(cellMargin).constraint
                }
                
                pictureView.hidden = false
            } else {
                pictureView.hidden = true
                
                selfBottomConstraints?.uninstall()
                self.snp_makeConstraints { (make) in
                    selfBottomConstraints = make.bottom.equalTo(textLabel.snp_bottom).offset(cellMargin).constraint
                }
            }
        }
    }
    
    private var selfBottomConstraints: Constraint?
    
    private lazy var textLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textAlignment: .Left, font: 15, maxWidth: SCREENW - 2*cellMargin)
    
    private lazy var pictureView: WBFristPagePictureView = WBFristPagePictureView()

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = RGB(red: 237, green: 237, blue: 237)
        
        addSubview(textLabel)
        
        textLabel.snp_makeConstraints { (make) in
            make.top.leading.equalTo(self).offset(cellMargin)
        }
        
        addSubview(pictureView)
        
        pictureView.snp_makeConstraints { (make) in
            make.leading.equalTo(self).offset(cellMargin)
            make.top.equalTo(textLabel.snp_bottom).offset(cellMargin)
        }
        
        self.snp_makeConstraints { (make) in
            selfBottomConstraints = make.bottom.equalTo(textLabel).offset(cellMargin).constraint
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
